package com.netease.nim.demo.session.viewholder;

import android.text.method.LinkMovementMethod;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.TextView;

import com.netease.nim.demo.common.adapter.TViewHolder;
import com.netease.nim.demo.session.emoji.MoonUtil;
import com.netease.nim.demo.session.helper.MessageHelper;
import com.netease.nim.demo.session.model.MsgListItem;
import com.netease.nim.demo.util.TimeUtil;
import com.shwread.android.qysw10000136.R;

public class MsgViewHolderNotification extends TViewHolder {

    protected TextView timeTextView;

    private TextView notificationTextView;

    @Override
    protected int getResId() {
        return R.layout.message_notification_view_item;
    }

    @Override
    public void inflate() {
        timeTextView = (TextView) view.findViewById(R.id.textViewTime);
        notificationTextView = (TextView) view.findViewById(R.id.textViewNotification);
    }

    @Override
    public void refresh(Object item) {
        final MsgListItem messageItem = (MsgListItem) item;
        setTimeTextView(messageItem);

        handleTextNotification(MessageHelper.getTeamNotificationText(messageItem.getMessage(), messageItem.getMessage().getSessionId()));
    }

    protected void setTimeTextView(MsgListItem messageItem) {
        if (messageItem.needShowTime) {
            timeTextView.setVisibility(View.VISIBLE);
        } else {
            timeTextView.setVisibility(View.GONE);
            return;
        }

        String text = TimeUtil.getTimeShowString(messageItem.getMessage()
                .getTime(), false);
        timeTextView.setText(text);
    }

    private void handleTextNotification(String text) {
        MoonUtil.identifyFaceExpressionAndATags(context, notificationTextView, text, ImageSpan.ALIGN_BOTTOM);
        notificationTextView.setMovementMethod(LinkMovementMethod.getInstance());
    }
}

